/**
 * 搜索模块
 */

import * as searchApi from '@/api/search'

export default {
  namespaced: true,
  state: {
    suggestionList: [],
    searchList: [],
  },
  mutations: {
    SET_SUGGESTION_LIST(state, newValue) {
      state.suggestionList = newValue;
    },
    SET_SEARCH_LIST(state, newValue) {
      state.searchList = newValue
    }
  },
  actions: {
    async updateSuggestionList(context, searchValue) {
      const res = await searchApi.getSuggestionList(searchValue);
      context.commit('SET_SUGGESTION_LIST', res);
    },

    async updateSearchList({ commit }, searchValue) {
      const res = await searchApi.getSearch(searchValue)
      commit('SET_SEARCH_LIST', res)
    }
  }
}
